package com.dropdb.demo.service.impl;

import com.dropdb.demo.bean.Brand;
import com.dropdb.demo.bean.vo.GetBrandListVO;
import com.dropdb.demo.bean.vo.GetBrandVO;
import com.dropdb.demo.mapper.BrandMapper;
import com.dropdb.demo.service.WxBrandService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * @author:cheyanjun
 * @date:2020/07/01 09:52
 */
@Service
public class WxBrandServiceImpl implements WxBrandService {

    @Autowired
    BrandMapper brandMapper;

    /**
     * 通过主键查询品牌详情
     * @param id
     * @return 该id对应的品牌详情
     */
    @Override
    public Brand getBrandDetail(Integer id) {
        Brand brand = brandMapper.selectByPrimaryKey(id);
        return brand;
    }

    /**
     * 获得所有品牌列表
     * @param page
     * @param size
     * @return
     */
    @Override
    public GetBrandListVO getBrandList(Integer page, Integer size) {
        PageHelper.startPage(page,size);
        //获得brandList
        List<GetBrandVO> getBrandVOS = brandMapper.selectBrandList();
        PageInfo<GetBrandVO> pageInfo = new PageInfo<>(getBrandVOS);
        //获得totalPages
        long total = pageInfo.getTotal();
        GetBrandListVO getBrandListVO = new GetBrandListVO();
        getBrandListVO.setBrandList(getBrandVOS);
        getBrandListVO.setTotalPages(total);
        return getBrandListVO;
    }
}
